package com.ruoyi.web.controller.compensationManagement;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.compensationManagement.domain.vo.RetiresPayrollImportVo;
import com.ruoyi.compensationManagement.domain.vo.StaffPayrollImportVo;
import com.ruoyi.system.service.ISysCommonService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.compensationManagement.domain.CompensationRetirespayroll;
import com.ruoyi.compensationManagement.service.ICompensationRetirespayrollService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 退休人员补贴工资账单Controller
 *
 * @author zy
 * @date 2022-10-07
 */
@RestController
@RequestMapping("/compensationManagement/retiresPayroll")
public class CompensationRetirespayrollController extends BaseController {
    @Autowired
    private ICompensationRetirespayrollService compensationRetirespayrollService;

    @Autowired
    private ISysCommonService sysCommonService;

    /**
     * 查询退休人员补贴工资列表
     */
    @PreAuthorize("@ss.hasPermi('compensationManagement:retiresPayroll:list')")
    @GetMapping("/list")
    public TableDataInfo list(CompensationRetirespayroll compensationRetirespayroll) {
        startPage();
        List<CompensationRetirespayroll> list = compensationRetirespayrollService.selectCompensationRetirespayrollList(compensationRetirespayroll);
        return getDataTable(list);
    }

    /**
     * 导出退休人员补贴工资列表
     */
    @PreAuthorize("@ss.hasPermi('compensationManagement:retiresPayroll:export')")
    @Log(title = "退休人员补贴工资", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CompensationRetirespayroll compensationRetirespayroll) {
        List<CompensationRetirespayroll> list = compensationRetirespayrollService.selectCompensationRetirespayrollList(compensationRetirespayroll);
        ExcelUtil<CompensationRetirespayroll> util = new ExcelUtil<CompensationRetirespayroll>(CompensationRetirespayroll.class);
        util.exportExcel(response, list, "退休人员补贴工资数据");
    }

    /**
     * 获取退休人员补贴工资详细信息
     */
    @PreAuthorize("@ss.hasPermi('compensationManagement:retiresPayroll:query')")
    @GetMapping(value = "/{retireespayrollId}")
    public AjaxResult getInfo(@PathVariable("retireespayrollId") Long retireespayrollId) {
        Map<String, Object> map = new HashMap<>();
        //获取固定项目
        map.put("fixedItems", compensationRetirespayrollService.selectCompensationRetirespayrollByRetireespayrollId(retireespayrollId));
        //获取浮动项目
        map.put("floatingItems", compensationRetirespayrollService.selectfFoatingItemsByRetireespayrollId(retireespayrollId));
        return AjaxResult.success(map);
    }

    /**
     * 新增退休人员补贴工资
     */
    @PreAuthorize("@ss.hasPermi('compensationManagement:retiresPayroll:add')")
    @Log(title = "退休人员补贴工资", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CompensationRetirespayroll compensationRetirespayroll) {
        return toAjax(compensationRetirespayrollService.insertCompensationRetirespayroll(compensationRetirespayroll));
    }

    /**
     * 修改退休人员补贴工资
     */
    @PreAuthorize("@ss.hasPermi('compensationManagement:retiresPayroll:edit')")
    @Log(title = "退休人员补贴工资", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CompensationRetirespayroll compensationRetirespayroll) {
        return toAjax(compensationRetirespayrollService.updateCompensationRetirespayroll(compensationRetirespayroll));
    }

    /**
     * 删除退休人员补贴工资
     */
    @PreAuthorize("@ss.hasPermi('compensationManagement:retiresPayroll:remove')")
    @Log(title = "退休人员补贴工资", businessType = BusinessType.DELETE)
    @DeleteMapping("/{retireespayrollIds}")
    public AjaxResult remove(@PathVariable Long[] retireespayrollIds) {
        return toAjax(compensationRetirespayrollService.deleteCompensationRetirespayrollByRetireespayrollIds(retireespayrollIds));
    }

    /**
     * 确定退休人员补贴工资表
     */
    @PreAuthorize("@ss.hasPermi('compensationManagement:retiresPayroll:determiningPayrollRetirees')")
    @Log(title = "确定退休人员补贴工资", businessType = BusinessType.UPDATE)
    @PutMapping("/determiningPayrollRetirees")
    public AjaxResult determiningPayrollRetirees(@RequestBody CompensationRetirespayroll compensationRetirespayroll) {
        return toAjax(compensationRetirespayrollService.determiningPayrollRetirees(compensationRetirespayroll));
    }

    /**
     * 工号查询姓名
     */
    @GetMapping(value = "/getNickNameByJobNumber/{jobNumber}")
    public AjaxResult getNickNameByJobNumber(@PathVariable("jobNumber") String jobNumber) {
        return AjaxResult.success(sysCommonService.getNickNameByJobNumber(jobNumber));
    }

    @Log(title = "退休人员补贴工资导入", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('compensationManagement:retiresPayroll:importData')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception {
        ExcelUtil<RetiresPayrollImportVo> util = new ExcelUtil<RetiresPayrollImportVo>(RetiresPayrollImportVo.class);
        List<RetiresPayrollImportVo> list = util.importExcel(file.getInputStream());
        String message = compensationRetirespayrollService.importRetireesPayroll(list);
        return AjaxResult.success(message);
    }

    /**
     * 导入模板下载
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) {
        ExcelUtil<RetiresPayrollImportVo> util = new ExcelUtil<RetiresPayrollImportVo>(RetiresPayrollImportVo.class);
        util.importTemplateExcel(response, "退休人员补贴导入");
    }
}
